package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service

public class NursingProjectServiceImpl implements NursingProjectService {
    @Resource
    private NursingProjectMapper nursingProjectMapper;
    /**
     * 护理项目分页查询
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @Override
    public PageResponse<NursingProjectVo> getByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        //1.设置分页参数
         PageHelper.startPage(pageNum, pageSize);
        //调用mapper 查询返回页数
        Page<NursingProject> nursingProjects = nursingProjectMapper.selectByPage(name,status);
        //把 实体类  转换成  响应实体类
        PageResponse<NursingProjectVo> response = PageResponse.of(nursingProjects, NursingProjectVo.class);
        //相应数据
        return response;
    }

    /**
     * 新增护理项目信息
     *
     * @param dto
     */
    @Override
    public void addNursingProject(NursingProjectDto dto) {
        //转换对象
        NursingProject project = BeanUtil.toBean(dto, NursingProject.class);
        //调用mapper
        nursingProjectMapper.insert(project);

    }

    /**
     * 根据id查询护理项目
     *
     * @param id
     * @return
     */
    @Override
    public NursingProjectVo getById(Long id) {
        //调用mapper
       NursingProject nursingProject =  nursingProjectMapper.selectById(id);
        NursingProjectVo vo = BeanUtil.toBean(nursingProject, NursingProjectVo.class);
        return vo;
    }

    /**
     * 更新护理项目
     *
     * @param dto
     */
    @Override
    public void update(NursingProjectDto dto) {
        //使用工具类转换对象
        NursingProject nursingProject = BeanUtil.toBean(dto, NursingProject.class);
        //调用mapper
        nursingProjectMapper.update(nursingProject);

    }

    /**
     * 启用禁用护理项目
     *
     * @param id
     * @param status
     */
    @Override
    public void enableOrDisable(Long id, Integer status) {
        //接收参数
        //调用mapper
        nursingProjectMapper.updateStatus(id, status);
    }

    /**
     * 根据ID删除项目信息
     *
     * @param id
     */
    @Override
    public void deleteById(Long id) {
        //TODO  什么情况下不能删除？
        nursingProjectMapper.deleteById(id);
    }

    /**
     * 查询所有护理项目
     *
     * @return
     */
    @Override
    public List<NursingProjectVo> findAll() {
        return null;


    }
}
